<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>优惠券</title>
        <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.js"></script>

    </head>

    <body>
        <div id="data"></div>
    <script>
    var id=1
    more(id)
    $(window).scroll(function () {loadmore($(this));});  
    
        
        var flag = true;                                                //标志，确定达到之后则停止,为了同时只进行一次加载操作  
        function loadmore(obj) {  
            var scrollTop = $(obj).scrollTop();                         //目前所在的位置  
            var scrollHeight = $(document).height();                    //文章一共有多长  
            var windowHeight = $(obj).height();                         //一页一共有多长  
            if (scrollHeight - (scrollTop + windowHeight) < 800) {      //20的意思是预留长度，总不能翻页到最底下才加载把~  
                if (flag) {  
                //alert(1);                                           //到底了在这里请求新的一页，这里可以放ajax获取新一页  
                flag = false;
                id=id+1
                more(id)
                } 
                
            }
            var header=true
            if (scrollTop>10) {      //20的意思是预留长度，总不能翻页到最底下才加载把~  
               // $(".itmes").css("background","#000")
                
            } else{
                //$(".itmes").css("background","#fff")
            }
        }
    function more(id) { 
       $.getJSON("__ROOT__/index/json",{"data":0,"r":"l","cid":0,"page":id}, function(data){ 
        for(x=0;x<data.data.length;x++){
            $("#data").append("<div class='itmes'><a href='./index?r=read&id="+data.data[x].id+"'><div class='itme'><img src='"+data.data[x].img+"'/><p class='title'>"+data.data[x].title+"</p><span  class='quan left'>券"+data.data[x].qprice+"元</span><a href='./index?r=read&id="+data.data[x].id+"' class='mai right'>立即购买</a><span class='center'>券后："+data.data[x].price+"元</span><div class='clear'></div></div></a></div>")
            flag = true;
        }
          
        });
    };        
    </script>
    </body>
</html>
